package com.zzyl.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    //分页条件查询
    @Override
    public PageResponse<NursingProjectVo> selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        //拿到name和status
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name, status);
        //转换vo
        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);
        return nursingProjectVoPageResponse;
    }

    //查询所有护理项目
    @Override
    public List<NursingProjectVo> selectAll() {
        List<NursingProject> nursingProjects = nursingProjectMapper.selectAll();
        return BeanUtil.copyToList(nursingProjects, NursingProjectVo.class);
    }

    //新增护理项目
    @Override
    public void create(NursingProject nursingProject) {
        nursingProjectMapper.insert(nursingProject);
    }

    //根据id查询护理
    @Override
    public NursingProject read(Long id) {
        NursingProject nursingProject =nursingProjectMapper.selectByPrimaryKey(id);
        return nursingProject;
    }

    //修改护理项目
    @Override
    public void update(NursingProject nursingProject) {
        nursingProjectMapper.updateByPrimaryKey(nursingProject);
    }

    //修改状态
    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id,status);

    }

    //删除
    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }
}
